<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content=
    "application/xhtml+xml; charset=iso-8859-1" />
    <title>
      About Devices
    </title>
    <link rel="stylesheet" type="text/css" href="../stylesheets/lfs.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="stylesheet" href="../stylesheets/lfs-print.css" type=
    "text/css" media="print" />
  </head>
  <body class="blfs" id="blfs-2020-04-02">
    <div class="navheader">
      <h4>
        Beyond Linux<sup>�</sup> From Scratch <span class="phrase">(System
        V</span> Edition) - Version 2020-04-02
      </h4>
      <h3>
        Chapter&nbsp;3.&nbsp;After LFS Configuration Issues
      </h3>
      <ul>
        <li class="prev">
          <a accesskey="p" href="firmware.html" title=
          "About Firmware">Prev</a>
          <p>
            About Firmware
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="skel.html" title=
          "Configuring for Adding Users">Next</a>
          <p>
            Configuring for Adding Users
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="config.html" title=
          "Chapter&nbsp;3.&nbsp;After LFS Configuration Issues">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Beyond Linux� From Scratch     (System V Edition) - Version 2020-04-02">
          Home</a>
        </li>
      </ul>
    </div>
    <div class="sect1" lang="en" xml:lang="en">
      <h1 class="sect1">
        <a id="postlfs-devices" name="postlfs-devices"></a>About Devices
      </h1>
      <p>
        Although most devices needed by packages in BLFS and beyond are set
        up properly by <span class="application">udev</span> using the
        default rules installed by LFS in <code class=
        "filename">/etc/udev/rules.d</code>, there are cases where the rules
        must be modified or augmented.
      </p>
      <p class="usernotes">
        User Notes: <a class="ulink" href=
        "http://wiki.linuxfromscratch.org/blfs/wiki/aboutdevices">http://wiki.linuxfromscratch.org/blfs/wiki/aboutdevices</a>
      </p>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          Multiple Sound Cards
        </h2>
        <p>
          If there are multiple sound cards in a system, the "default" sound
          card becomes random. The method to establish sound card order
          depends on whether the drivers are modules or not. If the sound
          card drivers are compiled into the kernel, control is via kernel
          command line parameters in <code class=
          "filename">/boot/grub/grub.cfg</code>. For example, if a system has
          both an FM801 card and a SoundBlaster PCI card, the following can
          be appended to the command line:
        </p>
        <pre class="screen">
<code class="literal">snd-fm801.index=0 snd-ens1371.index=1</code>
</pre>
        <p>
          If the sound card drivers are built as modules, the order can be
          established in the <code class="filename">/etc/modprobe.conf</code>
          file with:
        </p>
        <pre class="screen">
<code class="literal">options snd-fm801 index=0
options snd-ens1371 index=1</code>
</pre>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          <a id="usb-device-issues" name="usb-device-issues"></a>USB Device
          Issues
        </h2>
        <p>
          USB devices usually have two kinds of device nodes associated with
          them.
        </p>
        <p>
          The first kind is created by device-specific drivers (e.g.,
          usb_storage/sd_mod or usblp) in the kernel. For example, a USB mass
          storage device would be /dev/sdb, and a USB printer would be
          /dev/usb/lp0. These device nodes exist only when the
          device-specific driver is loaded.
        </p>
        <p>
          The second kind of device nodes (/dev/bus/usb/BBB/DDD, where BBB is
          the bus number and DDD is the device number) are created even if
          the device doesn't have a kernel driver. By using these "raw" USB
          device nodes, an application can exchange arbitrary USB packets
          with the device, i.e., bypass the possibly-existing kernel driver.
        </p>
        <p>
          Access to raw USB device nodes is needed when a userspace program
          is acting as a device driver. However, for the program to open the
          device successfully, the permissions have to be set correctly. By
          default, due to security concerns, all raw USB devices are owned by
          user root and group usb, and have 0664 permissions (the read access
          is needed, e.g., for lsusb to work and for programs to access USB
          hubs). Packages (such as SANE and libgphoto2) containing userspace
          USB device drivers also ship udev rules that change the permissions
          of the controlled raw USB devices. That is, rules installed by SANE
          change permissions for known scanners, but not printers. If a
          package maintainer forgot to write a rule for your device, report a
          bug to both BLFS (if the package is there) and upstream, and you
          will need to write your own rule.
        </p>
        <p>
          There is one situation when such fine-grained access control with
          pre-generated udev rules doesn't work. Namely, PC emulators such as
          KVM, QEMU and VirtualBox use raw USB device nodes to present
          arbitrary USB devices to the guest operating system (note: patches
          are needed in order to get this to work without the obsolete
          /proc/bus/usb mount point described below). Obviously, maintainers
          of these packages cannot know which USB devices are going to be
          connected to the guest operating system. You can either write
          separate udev rules for all needed USB devices yourself, or use the
          default catch-all "usb" group, members of which can send arbitrary
          commands to all USB devices.
        </p>
        <p>
          Before Linux-2.6.15, raw USB device access was performed not with
          /dev/bus/usb/BBB/DDD device nodes, but with /proc/bus/usb/BBB/DDD
          pseudofiles. Some applications (e.g., VMware Workstation) still use
          only this deprecated technique and can't use the new device nodes.
          For them to work, use the "usb" group, but remember that members
          will have unrestricted access to all USB devices. To create the
          fstab entry for the obsolete usbfs filesystem:
        </p>
        <pre class="screen">
<code class=
"literal">usbfs  /proc/bus/usb  usbfs  devgid=14,devmode=0660  0  0</code>
</pre>
        <div class="admon note">
          <img alt="[Note]" src="../images/note.png" />
          <h3>
            Note
          </h3>
          <p>
            Adding users to the "usb" group is inherently insecure, as they
            can bypass access restrictions imposed through the
            driver-specific USB device nodes. For instance, they can read
            sensitive data from USB hard drives without being in the "disk"
            group. Avoid adding users to this group, if you can.
          </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          Udev Device Attributes
        </h2>
        <p>
          Fine-tuning of device attributes such as group name and permissions
          is possible by creating extra <span class="application">udev</span>
          rules, matching on something like this. The vendor and product can
          be found by searching the <code class=
          "filename">/sys/devices</code> directory entries or using
          <span class="command"><strong>udevadm info</strong></span> after
          the device has been attached. See the documentation in the current
          <span class="application">udev</span> directory of <code class=
          "filename">/usr/share/doc</code> for details.
        </p>
        <pre class="screen">
<code class=
"literal">SUBSYSTEM=="usb_device", SYSFS{idVendor}=="05d8", SYSFS{idProduct}=="4002", \
  GROUP:="scanner", MODE:="0660"</code>
</pre>
        <div class="admon note">
          <img alt="[Note]" src="../images/note.png" />
          <h3>
            Note
          </h3>
          <p>
            The above line is used for descriptive purposes only. The scanner
            <span class="application">udev</span> rules are put into place
            when installing <a class="xref" href="../pst/sane.html" title=
            "SANE-1.0.29">SANE-1.0.29</a>.
          </p>
        </div>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          Devices for Servers
        </h2>
        <p>
          In some cases, it makes sense to disable <span class=
          "application">udev</span> completely and create static devices.
          Servers are one example of this situation. Does a server need the
          capability of handling dynamic devices? Only the system
          administrator can answer that question, but in many cases the
          answer will be no.
        </p>
        <p>
          If dynamic devices are not desired, then static devices must be
          created on the system. In the default configuration, the
          <code class="filename">/etc/rc.d/rcS.d/S10udev</code> boot script
          mounts a <code class="systemitem">tmpfs</code> partition over the
          <code class="filename">/dev</code> directory. This problem can be
          overcome by mounting the root partition temporarily:
        </p>
        <div class="admon warning">
          <img alt="[Warning]" src="../images/warning.png" />
          <h3>
            Warning
          </h3>
          <p>
            If the instructions below are not followed carefully, your system
            could become unbootable.
          </p>
        </div>
        <pre class="userinput">
<kbd class="command">mount --bind / /mnt
cp -a /dev/* /mnt/dev
rm /etc/rc.d/rcS.d/{S10udev,S50udev_retry}
umount /mnt</kbd>
</pre>
        <p>
          At this point, the system will use static devices upon the next
          reboot. Create any desired additional devices using <span class=
          "command"><strong>mknod</strong></span>.
        </p>
        <p>
          If you want to restore the dynamic devices, recreate the
          <code class=
          "filename">/etc/rc.d/rcS.d/{S10udev,S50udev_retry}</code> symbolic
          links and reboot again. Static devices do not need to be removed
          (console and null are always needed) because they are covered by
          the <code class="systemitem">tmpfs</code> partition. Disk usage for
          devices is negligible (about 20&ndash;30 bytes per entry.)
        </p>
      </div>
      <div class="sect2" lang="en" xml:lang="en">
        <h2 class="sect2">
          <a id="dev-dvd" name="dev-dvd"></a>Devices for DVD Drives
        </h2>
        <p>
          If the initial boot process does not set up the <code class=
          "systemitem">/dev/dvd</code> device properly, it can be installed
          using the following modification to the default udev rules. As the
          <code class="systemitem">root</code> user, run:
        </p>
        <pre class="userinput">
<kbd class="command">sed '1d;/SYMLINK.*cdrom/ a\
KERNEL=="sr0", ENV{ID_CDROM_DVD}=="1", SYMLINK+="dvd", OPTIONS+="link_priority=-100"' \
/lib/udev/rules.d/60-cdrom_id.rules &gt; /etc/udev/rules.d/60-cdrom_id.rules</kbd>
</pre>
      </div>
      <p class="updated">
        Last updated on 2020-03-25 10:07:11 -0500
      </p>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="firmware.html" title=
          "About Firmware">Prev</a>
          <p>
            About Firmware
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="skel.html" title=
          "Configuring for Adding Users">Next</a>
          <p>
            Configuring for Adding Users
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="config.html" title=
          "Chapter&nbsp;3.&nbsp;After LFS Configuration Issues">Up</a>
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title=
          "Beyond Linux� From Scratch     (System V Edition) - Version 2020-04-02">
          Home</a>
        </li>
      </ul>
    </div>
  </body>
</html>
